package POS.Interface.data;

import java.sql.*;
import java.util.logging.*;

/**
 * A POS System for a small restaurant.
 *
 * Maeghan Colvin and Jennifer Haveman CSC 289 0B01 February 24, 2014
 */
public class EateryDBConnection
{

    /**
     *
     * @return
     */
    public static ResultSet getTableResults(String sqlStatement)
    {
        try
        {
            // Connect to database
            String url = "jdbc:derby:EateryDB";
            Connection conn = DriverManager.getConnection(url);
            Statement stmt = conn.createStatement(
                    ResultSet.TYPE_SCROLL_INSENSITIVE,
                    ResultSet.CONCUR_READ_ONLY);

            // Get ResultSet
            ResultSet results = stmt.executeQuery(sqlStatement);
            return results;
        }
        catch (SQLException ex)
        {
            Logger.getLogger(EateryDBConnection.class.getName()).
                    log(Level.SEVERE,
                    null,
                    ex);
            return null;
        }
        finally
        {

        }
    }

    /**
     *
     * @return
     */
    public static boolean isEmployeeThere(int employeeID, String sqlStatement)
    {
        boolean found = false;
        
        try
        {
            // Connect to database
            String url = "jdbc:derby:EateryDB";
            Connection conn = DriverManager.getConnection(url);
            Statement stmt = conn.createStatement(
                    ResultSet.TYPE_SCROLL_INSENSITIVE,
                    ResultSet.CONCUR_READ_ONLY);

            // Get ResultSet
            ResultSet results = stmt.executeQuery(sqlStatement);
            
            // Search ResultSet to find if data was found
            if (results.next())
            {
                found = true;
            }
            return found;
        }
        catch (SQLException ex)
        {
            Logger.getLogger(EateryDBConnection.class.getName()).
                    log(Level.SEVERE,
                    null,
                    ex);
            return found;
        }
    }
}
